package com.heg.api.util;

import java.util.Map;
import java.util.HashMap;

import com.cloopen.rest.sdk.CCPRestSmsSDK;

/**
 * 短信发送平台
 * @author 邓绪招
 * @time 2016-04-04
 */
public class SmsPlatformUtils {
	
	//测试sandboxapp.cloopen.com 运营 app.cloopen.com
	public static final String SMS_INIT_SERVER_URL_APP = "sandboxapp.cloopen.com";  //初始化服务器地址（url） 上线
	public static final String SMS_INIT_SERVER_PORT = "8883";     //初始化服务器端口
	public static final String SMS_INIT_PRI_ACCOUNT = "aaf98f894e770027014e774389a500a4";      // 初始化主账号
	public static final String SMS_INIT_PRI_ACCOUNT_TOKEN = "368cea14609e4325ac59802ae0b131c7";      //初始化主账号令牌
	public static final String SMS_INIT_APP_ID = "aaf98f89544cd9d9015467ca88361a5d";     //初始化应用ID
	
	/**
	 * 发送验证码
	 * @param telNumber  电话号码（多个电话号码以逗号分隔）
	 * @param templateId   模板Id  验证码模板为1
	 * @param datas 传入参数（根据具体模板而定）
	 * @return  发送成功返回true 反之返回false
	 */
	public static Map<String, Object> sendSecCode(String telNumber, String templateId, String[] datas){
		Map<String, Object> result = new HashMap<String, Object>();
		//初始化并创建短信平台sdk
		CCPRestSmsSDK restSmsSDK = new CCPRestSmsSDK();
		//初始化服务器地址和端口
		restSmsSDK.init(SMS_INIT_SERVER_URL_APP, SMS_INIT_SERVER_PORT);
		//初始化服务器地址和端口
		restSmsSDK.setAccount(SMS_INIT_PRI_ACCOUNT, SMS_INIT_PRI_ACCOUNT_TOKEN);
		//初始化应用ID
		restSmsSDK.setAppId(SMS_INIT_APP_ID);
		//初始化应用ID
		result = restSmsSDK.sendTemplateSMS(telNumber, templateId, datas);
		return result;
	}
	
	public static void main(String[] args) {
		Map<String, Object> result = sendSecCode("15875538591", "1", new String[]{"1234", "1"});
		System.out.println(result);
	}
	
	/**
	 * 短信发送
	 * @param telNumber  电话号码（多个电话号码以逗号分隔）
	 * @param templateId   模板Id  验证码模板为1
	 * @param datas 传入参数（根据具体模板而定）
	 * @return  发送成功返回true 反之返回false
	 */
	public static Map<String, Object> send_Messages(String telNumber, String templateId, String[] datas){
		Map<String, Object> result = new HashMap<String, Object>();
		///初始化并创建短信平台sdk
		CCPRestSmsSDK restSmsSDK = new CCPRestSmsSDK();
		//初始化服务器地址和端口
		restSmsSDK.init(SMS_INIT_SERVER_URL_APP, SMS_INIT_SERVER_PORT);
		//初始化主账号和主账号令牌
		restSmsSDK.setAccount(SMS_INIT_PRI_ACCOUNT, SMS_INIT_PRI_ACCOUNT_TOKEN);
		//初始化应用ID
		restSmsSDK.setAppId(SMS_INIT_APP_ID);
		//调用发送方法
		result = restSmsSDK.sendTemplateSMS(telNumber, templateId, datas);
		return result;
	}

}
